import React, { useState, useEffect } from 'react';
import { Cascader } from 'antd';
import { connect } from 'umi';
/**
 * 用户选择器
 */


const UserSelect = (props) => {
  const { form, select, placeholder, onChange, dispatch, label } = props;
  const fieldNames = { label: 'departmentName', value: 'qywxDepartmentId', children: 'subDepartmentList' };
  const [list, setList] = useState([])
  const fetchGetUser = () => {
    dispatch({
      type: 'weCom/fetchQywxDepartment',
      callback: (e) => {
        setList(e)
      }
    });
  }
  console.log(list, '1231231')
  useEffect(() => {
    fetchGetUser()
  }, [])

  // 返回结果
  return (
    <Cascader
      allowClear
      expandTrigger="hover"
      fieldNames={fieldNames}
      options={list}
      placeholder={placeholder || `选择${label}`}
      showSearch={{
        filter: (inputValue, path) =>
          filter(inputValue, path, fieldNames ? fieldNames.label : 'label'),
      }}
      onChange={(val) => onChange && onChange(val, form)}
    />
  );
};

export default connect(({ loading }) => ({
  loading: loading.effects['weCom/fetchQywxDepartment'],
}))(UserSelect);
